package com.crom.android.lottebaseball;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.SystemClock;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.CheckBox;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.crom.android.lottebaseball.AlarmService_Service;

public class settingMenu extends Activity implements RadioGroup.OnCheckedChangeListener{
	
	public static final String KEY_NO_NOTI = "checkBox_pref";
	public static final String KEY_NOTI_TIME = "notitime_pref";
	static SharedPreferences prefs ;
	
	RadioButton min_3;
	RadioButton min_8;
	RadioButton min_15;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.settings);
		
		CheckBox box = (CheckBox) findViewById(R.id.checkBox1);
		RadioGroup rg = (RadioGroup) findViewById(R.id.radioGroup);
		min_3 = (RadioButton) findViewById(R.id.radio3min);
		min_8 = (RadioButton) findViewById(R.id.radio8min);
		min_15 = (RadioButton) findViewById(R.id.radio15min);
   	    rg.setOnCheckedChangeListener(this);
   	    
		prefs = getSharedPreferences("PrefName", MODE_PRIVATE);
		
   	    box.setChecked(prefs.getBoolean(KEY_NO_NOTI, true));
   	    int selectedNum = (prefs.getInt(KEY_NOTI_TIME,8));
   	    switch(selectedNum){
   	    
   	    case 3:
   	    	min_3.setChecked(true);
   	    	break;
   	    	
   	    case 8:
   	    	min_8.setChecked(true);	
   	    	break;
   	    	
   	    case 15:
   	    	min_15.setChecked(true);
   	    	break;
   	    }
   	    
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		
	}

	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
		
		prefs = getSharedPreferences("PrefName", Activity.MODE_PRIVATE);
		SharedPreferences.Editor editor = prefs.edit();
		
		CheckBox box = (CheckBox) findViewById(R.id.checkBox1);
		editor.putBoolean(KEY_NO_NOTI, box.isChecked());
		
		editor.commit();
		
		
	}

	@Override
	public void onCheckedChanged(RadioGroup group, int checkedId) {
		// TODO Auto-generated method stub
		
		prefs = getSharedPreferences("PrefName", MODE_PRIVATE);
		SharedPreferences.Editor editor = prefs.edit();
		
		
		switch(checkedId){
		
		case R.id.radio3min:
			editor.putInt(KEY_NOTI_TIME, 3);
			break;
		case R.id.radio8min:
			editor.putInt(KEY_NOTI_TIME, 8);	
			break;
		case R.id.radio15min:
			editor.putInt(KEY_NOTI_TIME, 15);	
			break;
		}
		
		editor.commit();
		
	}
	
	

}
